﻿using Knlght.CH.Domain.IRepository;
using Knlght.Domain;
using Knlght.Model.links;
using System;
using System.Linq.Expressions;

namespace Knlght.Service
{
    public class LinkInfoService:ServiceBase
    {
        public ActionResponse Add(LinkInfo model)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILinkInfoRepository>();             
                return rp.Add(model);
            });
        }
        public ActionResponse Update(LinkInfo model)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILinkInfoRepository>();
                return rp.Update(model);
            });
        }
        public ActionResponse Update(QueryRequest<LinkInfo> query, Expression<Func<LinkInfo, LinkInfo>> key)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILinkInfoRepository>();
                return rp.UpdateToList(query, key);
            });
        }
        public ActionResponse Remove(QueryRequest<LinkInfo> query)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILinkInfoRepository>();
                return rp.Delete(query);
            });
        }
   
        public ItemResponse<LinkInfo> GetModel(QueryRequest<LinkInfo> query)
        {
            return GetModel<LinkInfo>(()=> {
                var rp = getRepository<ILinkInfoRepository>();
                return rp.GetModel(query);
            });
        }
        public ListResponse<LinkInfo> GetList()
        {
            return GetList<LinkInfo>(() => {
                var rp = getRepository<ILinkInfoRepository>();
                return rp.GetList();
            });
        }
        public ListResponse<LinkInfo> GetList(QueryRequest<LinkInfo> query)
        {
            return GetList<LinkInfo>(() => {
                var rp = getRepository<ILinkInfoRepository>();
                return rp.GetList(query);
            });
        }
        public PagingResponse<LinkInfo> Paging(PagingRequest<LinkInfo> request)
        {
            return GetPaging<LinkInfo>(() => {
                //总记录
                int totalRecord = 0;
                var rp = getRepository<ILinkInfoRepository>();
                return new PagingList<LinkInfo>()
                {
                    Models = rp.GetList(request.PageSize, request.PageIndex, out totalRecord, request.Query),
                    TotalModels = totalRecord,
                    TotalPages = (totalRecord + request.PageSize - 1) / request.PageSize
                };
            });
        }
    }
}
